Skip to content

Add IMX519 driver and device tree overlay - #4548

Merged
pelwell merged 5 commits into
raspberrypi:rpi-5.10.yfrom
ArduCAM:arducam_imx519
Sep 30, 2021
Merged

pelwell merged 5 commits into
raspberrypi:rpi-5.10.yfrom
ArduCAM:arducam_imx519

Conversation

@ArduCAM

@ArduCAM ArduCAM commented Aug 26, 2021

Copy link
Copy Markdown

No description provided.

@6by9

6by9 commented Aug 26, 2021

Copy link
Copy Markdown
Contributor

Initial comments before I start reviewing the driver.

A couple of checkpatch warnings (I do have --strict enabled by default)

ImportError: No module named ply
WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#9: 
which can be disabled through the ENABLE_VCM_DUMMY macro (enabled by default).

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#25: 
new file mode 100644

WARNING: Possible repeated word: 'all'
#74: FILE: Documentation/devicetree/bindings/media/i2c/imx519.yaml:45:
+      Must be released (set high) after all all supplies and INCK are applied.

WARNING: DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.rst

CHECK: Please don't use multiple blank lines
#1060: FILE: drivers/media/i2c/imx519.c:868:
+
+

CHECK: Alignment should match open parenthesis
#1498: FILE: drivers/media/i2c/imx519.c:1306:
+static int ak7371_i2c_write(struct imx519 *imx519,
+	u8 addr, u16 data, u8 size)

CHECK: Please don't use multiple blank lines
#1519: FILE: drivers/media/i2c/imx519.c:1327:
+
+

Device tree bindings should always be in a separate patch from the driver - they are handled via different trees in mainline, and DT can describe things about the hardware that the driver doesn't support.

Is there anything different about your version of the module to the standard Sony one? If not then it should use Sony's vendor prefix and not an Arducam one.

As discussed by email, VCM control is supported by the framework by using a lens-focus phandle link from the sensor to the lens driver, and it will be automatically created as an extra v4l-subdev node. You'll probably want a link between the VCM driver and the cam1_reg regulator that controls the sensor power, similar to how https://elixir.free-electrons.com/linux/latest/source/drivers/media/i2c/dw9768.c handles it.
Is there actually a difference between AK7371 and AK7375?

@6by9 6by9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number of these look to be due to copying IMX477 but not supporting some of the features. This leaves a number of chunks of effectively dead code around.

Comment thread drivers/media/i2c/Makefile Resolved
Comment thread drivers/media/i2c/imx519.c Resolved
Comment thread drivers/media/i2c/imx519.c Resolved
Comment thread drivers/media/i2c/imx519.c Resolved
Comment thread drivers/media/i2c/imx519.c Resolved
Comment thread drivers/media/i2c/imx519.c Resolved
Comment thread drivers/media/i2c/imx519.c Resolved
Comment thread drivers/media/i2c/imx519.c Outdated

#define IMX519_XCLK_FREQ 24000000

#define IMX519_DEFAULT_LINK_FREQ 648000000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor note that if this is actually correct, then it exceeds the spec for CSI-2 which is 1Gbit/s/lane, which equates to 500MHz as it is DDR.
Unicam (the CSI-2 receiver) does normally cope with slightly higher data rates, but technically you're exceeding the spec.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be my calculation error.
The actual frequency was 525Mhz before, but it has been reduced to 493.5Mhz.

@6by9

6by9 commented Aug 26, 2021

Copy link
Copy Markdown
Contributor

For mainline, patches need to have a named author - https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin

Also MAINTAINERS hasn't been updated to report who is maintaining the DT binding and driver files.

@ArduCAM

ArduCAM commented Aug 26, 2021

Copy link
Copy Markdown
Author

Hi 6by9

Thank you for your review and suggestions,
There is no difference in control between AK7371 and AK7375 (at least the functions I use are not).

We will resolve your proposed amendments as soon as possible.

Regarding the VCM driver, since the current framework is still a bit imperfect, we plan to use this temporary solution. Is this acceptable?

@6by9

6by9 commented Aug 26, 2021

Copy link
Copy Markdown
Contributor

Regarding the VCM driver, since the current framework is still a bit imperfect, we plan to use this temporary solution. Is this acceptable?

Which part of the framework do you have an issue with? Yes the control will be under a different subdev node, but that's how it will end up being anyway.

@ArduCAM

ArduCAM commented Aug 26, 2021

Copy link
Copy Markdown
Author

When the camera is turned on again, it will write the last control value:

ret = __v4l2_ctrl_handler_setup(imx477->sd.ctrl_handler);

But at present, when the camera is turned on, other subdevs are not notified, which makes it impossible to restore the control value of VCM.
is it right? Maybe I missed something?

@6by9

6by9 commented Aug 26, 2021

Copy link
Copy Markdown
Contributor

But at present, when the camera is turned on, other subdevs are not notified, which makes it impossible to restore the control value of VCM.
is it right? Maybe I missed something?

As per my comment

As discussed by email, VCM control is supported by the framework by using a lens-focus phandle link from the sensor to the lens driver, and it will be automatically created as an extra v4l-subdev node. You'll probably want a link between the VCM driver and the cam1_reg regulator that controls the sensor power, similar to how https://elixir.free-electrons.com/linux/latest/source/drivers/media/i2c/dw9768.c handles it.

Both the lens driver and sensor drivers need to make a request to the regulator driver for the sensor/lens to be powered on when required. The regulator driver will reference count the requests, and only power down when neither want it.
Each can therefore guarantee that the power will remain on whilst in use, and know when they need to reinitialise.

There is a need to be careful that a regulator request to power down and up does not necessarily result in an actual reset if there are other users of the regulator. Most sensors use the software reset at the start of their initialisation sequence anyway, so that's not normally an issue.

@ArduCAM

ArduCAM commented Aug 27, 2021

Copy link
Copy Markdown
Author

Both the lens driver and sensor drivers need to make a request to the regulator driver for the sensor/lens to be powered on when required. The regulator driver will reference count the requests, and only power down when neither want it.
Each can therefore guarantee that the power will remain on whilst in use, and know when they need to reinitialise.

I understand.
My original purpose was this:
Open the camera through the video node (using libcamera or other methods), at this time use the v4l2-ctl command to set the focus value, and when the video node is closed and turned on again, the focus value set last time can be restored.
Since the v4l2-ctl command will execute the Open -> Settings Control -> Close process, it seems that the goal we want cannot be achieved.

I noticed that regulator_register_notifier may achieve my purpose, but I am not sure whether this is the correct usage.

@ArduCAM

ArduCAM commented Aug 27, 2021 •

Copy link
Copy Markdown
Author

For mainline, patches need to have a named author - https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin

Also MAINTAINERS hasn't been updated to report who is maintaining the DT binding and driver files.

Not sure if the link in MAINTAINERS is correct...
https://github.com/ArduCAM/linux/blob/0002a4e39a4c062526927d0fc3588edf009033b5/MAINTAINERS#L16379

@pelwell

pelwell commented Aug 27, 2021

Copy link
Copy Markdown
Contributor

I'm happy with this PR from an overlay, Kconfig, Makefile and commit partitioning perspective - I'll leave the driver reviewing to @6by9.

The pachyderm in the parlour is that we expect non-Pi-specific drivers to be submitted upstream - we can't commit to supporting them ourselves indefinitely. What are your plans for upstreaming?

@ArduCAM

ArduCAM commented Aug 27, 2021

Copy link
Copy Markdown
Author

Hi pelwell,
Thanks for your review.

I’m not sure about the workflow here,
At first I worried that submitting the same thing in two places would cause conflicts. If there is no conflict, I think we can try to submit it to git://linuxtv.org/media_tree.git

@6by9

6by9 commented Aug 27, 2021

Copy link
Copy Markdown
Contributor

My original purpose was this:
Open the camera through the video node (using libcamera or other methods), at this time use the v4l2-ctl command to set the focus value, and when the video node is closed and turned on again, the focus value set last time can be restored.
Since the v4l2-ctl command will execute the Open -> Settings Control -> Close process, it seems that the goal we want cannot be achieved.
I noticed that regulator_register_notifier may achieve my purpose, but I am not sure whether this is the correct usage.

OK, so it's effectively the "default" case where the sensor is being used and the lens not being cared about by a particular app, so it needs to be restored when the sensor is powered up.

In which case I believe you are correct that regulator_register_notifier looking for event REGULATOR_EVENT_ENABLE should achieve what you want, and initialise the VCM from that notifier (do not call pm_runtime or enable the regulator from there).
ak7375_vcm_resume then wants to either enable the regulator (which will call the notifier), or in the case of no regulator being configured it should do the setup there. This is an existing VCM driver, therefore you can't make the regulator mandatory, so it needs to be requested via regulator_get_optional (slightly annoyingly there appears to be no devm_ version of that - such is life).

Using devm_regulator_register_notifier to get a managed version may be more useful, but there are potential race conditions on shutdown if you're not careful (state structures may be destroyed whilst the notifier is still registered - see c6fa884, although that was interrupts rather than regulators).

I’m not sure about the workflow here,
At first I worried that submitting the same thing in two places would cause conflicts. If there is no conflict, I think we can try to submit it to git://linuxtv.org/media_tree.git

I was offering to do a first pass review on the driver before it was sent upstream. They are likely to have their own comments, but knocking out the initial obvious things saves some time and effort there (I find it isn't necessarily the easiest mailing list to deal with).
Embedding the VCM driver into the sensor driver was not going to be acceptable to them, but you could ask the question on linux-media whether the proposed solution is acceptable.

Not sure if the link in MAINTAINERS is correct...
https://github.com/ArduCAM/linux/blob/0002a4e39a4c062526927d0fc3588edf009033b5/MAINTAINERS#L16379

This should be as if it is being submitted upstream, so git git://linuxtv.org/media_tree.git.
You don't need a W entry.

@6by9 6by9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DT bindings needs to come before the driver. MAINTAINERS normally gets updated once with the bindings to add both bindings and the driver files, eg torvalds/linux@8a97a46

By copying imx477 I'm afraid you've got caught in the cross-fire slightly between us and mainline over supporting multiple streams (ie image with embedded metadata). Mainline still haven't resolved this, although patches have been kicked around recently. We adopted just advertising 2 pads for the two streams, but that isn't be acceptable to upstream.

If you're looking to upstream this, then the references to METADATA_PAD need to be removed, and all the pad index checks become if (thing->pad) instead of if (things->pad >= NUM_PADS). I'm happy to accept an additional patch to our tree which adds the second pad back in, and proper support for the streams can be added when they've decided how to do it.

Comment thread drivers/media/i2c/imx519.c Resolved
Comment thread drivers/media/i2c/imx519.c Resolved
Add YAML device tree binding for IMX519 CMOS image sensor, and
the relevant MAINTAINERS entries.

Signed-off-by: Lee Jackson <info@arducam.com>
@ArduCAM

ArduCAM commented Aug 30, 2021

Copy link
Copy Markdown
Author

Hi 6by9
Thank you very much for your review and suggestions,
I realize that I have made a lot of stupid mistakes that have caused you unnecessary trouble, and I am sorry for that.

@6by9

6by9 commented Sep 3, 2021

Copy link
Copy Markdown
Contributor

No problems. I'm happy to review drivers before submission upstream as I recognise that it is a fairly steep learning curve.
Interactions on the linux-media mailing list can be slow and tedious, and often disheartening, with a number of seemingly unwritten rules that you have to pick up over time.

My comment still applies over the METADATA_PAD - that isn't the way upstream are going to want it, so simplest to implement just exposing video initially. Add the metadata pad later on if we have code that will parse it.
I need to investigate the upstream multiplexed stream support and see how it is going to work - https://patchwork.linuxtv.org/project/linux-media/list/?series=6197 / https://git.kernel.org/pub/scm/linux/kernel/git/tomba/linux.git/log/?h=multistream/work-v8

@ArduCAM

ArduCAM commented Sep 6, 2021

Copy link
Copy Markdown
Author

Yes, I saw your description of METADATA_PAD, I was thinking maybe we have a chance to merge it into the Raspberry Pi kernel first?

Adds a driver for the 16MPix IMX519 CSI2 sensor.
Whilst the sensor supports 2 or 4 CSI2 data lanes, this driver
currently only supports 2 lanes.

The following Bayer modes are currently available:

4656x3496 10-bit @ 10fps
3840x2160 10-bit (cropped) @ 21fps
2328x1748 10-bit (binned) @ 30fps
1920x1080 10-bit (cropped/binned) @ 60fps
1280x720 10-bit (cropped/binned) @ 120fps

Signed-off-by: Lee Jackson <info@arducam.com>
@ArduCAM

ArduCAM commented Sep 14, 2021

Copy link
Copy Markdown
Author

Hi @6by9
If we want to merge into the kernel of raspberry pi first, do we need to delete MATEDATA_PAD?

@6by9

6by9 commented Sep 14, 2021

Copy link
Copy Markdown
Contributor

Sorry, I'd missed your previous comment.

We try to minimise any differences to mainline, unless a feature or change is totally unacceptable to mainline (eg the abuse of pads for the metadata stream).
Even those changes should be made as an extra patch on top of what should be acceptable to mainline.

So it really would be preferable to have the METADATA_PAD change split out as a separate patch. You need to do that for mainline anyway.

ArduCAM and others added 3 commits September 15, 2021 09:17
This commit updates the imx519 driver to adverise support for embedded
data streams.

The imx519 sensor subdevice overloads the media pad to differentiate
between image stream (pad 0) and embedded data stream (pad 1) when
performing the v4l2_subdev_pad_ops functions.

Signed-off-by: Lee Jackson <info@arducam.com>
Include the driver module for the IMX519.

Signed-off-by: Lee Jackson <info@arducam.com>
Added overlays for enabling IMX519 and add the
relevant information to the README.

Signed-off-by: Lee Jackson <info@arducam.com>
@ArduCAM

ArduCAM commented Sep 16, 2021

Copy link
Copy Markdown
Author

Hi @6by9
Thanks for your suggestion, do you think this patch is okay?

@ArduCAM

ArduCAM commented Sep 29, 2021

Copy link
Copy Markdown
Author

Hi @6by9
Just in case you missed this.

@6by9

6by9 commented Sep 30, 2021

Copy link
Copy Markdown
Contributor

Apologies, I had missed the update again.

That looks good now. There may be a couple of quibbles upstream over minor details of the implementation, but most of it looks fine to me.
I'm trusting that it actually produces images and the controls do what they're supposed to.

@pelwell
pelwell merged commit 1faafd9 into raspberrypi:rpi-5.10.y Sep 30, 2021
@pelwell

pelwell commented Oct 1, 2021

Copy link
Copy Markdown
Contributor

These patches required some adjustments for the newer kernels, but they're in rpi-5.14.y and rpi-5.15.y now (along with blank lines after the first lines of the commit messages).

popcornmix added a commit to raspberrypi/firmware that referenced this pull request Oct 6, 2021
See: raspberrypi/linux#4571

kernel: rpi-5.10.y fixups
See: raspberrypi/linux#4608

kernel: Add IMX519 driver and device tree overlay
See: raspberrypi/linux#4548

kernel: dtoverlays: Add overlay for ST7735R (160x128) TinyDRM driver
See: raspberrypi/linux#4615
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Oct 6, 2021
See: raspberrypi/linux#4571

kernel: rpi-5.10.y fixups
See: raspberrypi/linux#4608

kernel: Add IMX519 driver and device tree overlay
See: raspberrypi/linux#4548

kernel: dtoverlays: Add overlay for ST7735R (160x128) TinyDRM driver
See: raspberrypi/linux#4615
@ArduCAM

ArduCAM commented Oct 14, 2021

Copy link
Copy Markdown
Author

Hi @pelwell

These patches required some adjustments for the newer kernels, but they're in rpi-5.14.y and rpi-5.15.y now (along with blank lines after the first lines of the commit messages).

Do I need to make any changes to this?

@pelwell

pelwell commented Oct 14, 2021

Copy link
Copy Markdown
Contributor

You tell me - it all compiles, but is otherwise untested.

@ArduCAM

ArduCAM commented Oct 14, 2021

Copy link
Copy Markdown
Author

Got it, I will test it on the new version of the kernel.

@ArduCAM

ArduCAM commented Oct 19, 2021

Copy link
Copy Markdown
Author

Hi @pelwell
After testing everything looks fine.
2021-10-18-103352_1920x1080_scrot
2021-10-19-031608_1920x1080_scrot

@pelwell

pelwell commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

Excellent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants